package com.wealth.scsj.p_app.view.activity.loginmodel;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.alibaba.fastjson.JSONObject;
import com.vondear.rxtools.RxSPTool;
import com.wealth.scsj.p_app.R;
import com.wealth.scsj.p_app.config.RxSPConfig;
import com.wealth.scsj.p_app.utils.Tool;
import com.wealth.scsj.p_app.view.activity.BaseActivity;


import okhttp3.MediaType;
import okhttp3.RequestBody;


/**
 * 忘记密码设置新登录密码
 */
public class ForgetPasswordActivity extends BaseActivity implements View.OnClickListener {

    /**  */
    private EditText mPhoneEt;
    /**
     * 发送验证码：
     */
    private Button mSendCodeBtn;
    /**  */
    private EditText mRegisterCodeEt;
    /**  */
    private EditText mPswEt;
    /**
     * 确认
     */
    private Button mCommitBtn;


    @Override
    protected void createView(Bundle savedInstanceState) {
        setContentView(R.layout.activity_forget_password);
//        initToolbar();
 //       setToolbarTitle("重置登录密码");
//        hasBack(true);
    }

    @Override
    protected void initView() {

        mPhoneEt = (EditText) findViewById(R.id.phone_et);
        mSendCodeBtn = (Button) findViewById(R.id.send_code_btn);
        mRegisterCodeEt = (EditText) findViewById(R.id.register_code_et);
        mPswEt = (EditText) findViewById(R.id.psw_et);
        mCommitBtn = (Button) findViewById(R.id.commit_btn);
    }

    @Override
    protected void initListener() {
        mSendCodeBtn.setOnClickListener(this);
        mCommitBtn.setOnClickListener(this);

    }

    @Override
    protected void initData() {

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            default:
                break;
            case R.id.send_code_btn:
                if(!Tool.isPhoneNumber(mPhoneEt.getText().toString().trim())){
                    mPhoneEt.setError("请输入正确的手机号");
                    return;
                }
                if(!mPhoneEt.getText().toString().trim().equals(RxSPTool.getString(this, RxSPConfig.USER_PHONE))){
                    mPhoneEt.setError("请输入当前登录的手机号");
                    return;
                }
                JSONObject jsonObject = new JSONObject();
                jsonObject.put("phone", RxSPTool.getString(this, RxSPTool.getString(this, RxSPConfig.USER_PHONE)));
                RequestBody requestBody = RequestBody.create(MediaType.parse("application/json;charset=utf-8"),jsonObject.toString());
                break;
            case R.id.commit_btn:
                JSONObject jsonObject1 = new JSONObject();
                jsonObject1.put("phone", RxSPTool.getString(this, RxSPTool.getString(this, RxSPConfig.USER_PHONE)));
                jsonObject1.put("code",mRegisterCodeEt.getText());
                jsonObject1.put("newPassword", mPswEt.getText());

                RequestBody requestBody1 = RequestBody.create(MediaType.parse("application/json;charset=utf-8"),jsonObject1.toString());
                break;
        }
    }


}
